package com.dinnerorders.core.services.impl;

import com.dinnerorders.common.models.Menu;
import com.dinnerorders.common.services.MenuService;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.TypedQuery;
import java.util.List;

/**
 * @author Sergey Nalivko e-mail: snalivko93@gmail.com
 */
public class MenuServiceImpl extends BaseDAO<Menu> implements MenuService {

    @Override
    @Transactional
    public void save(Menu menu) {
        entityManager.persist(menu);
    }

    @Override
    @Transactional
    public List<Menu> loadAll() {
        TypedQuery<Menu> query = entityManager.createNamedQuery(Menu.LOAD_ALL_MENUS, Menu.class);
        return query.getResultList();
    }
}